package com.lee9213.conference.track.management.handler;

import com.lee9213.conference.track.management.entity.TalkEntity;
import com.lee9213.conference.track.management.entity.TrackEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lee9213@163.com
 * @version 1.0
 * @date 2018-07-11 23:34
 */
public class FilterChain {

    private List<Filter> filters = new ArrayList<>();
    private int index = 0;

    public FilterChain addFilter(Filter filter) {
        this.filters.add(filter);
        return this;
    }

    public void doFilter(List<TalkEntity> allTalkEntities, TrackEntity trackEntity) {
        if (filters.size() <= 0 || index >= filters.size()) {
            return;
        }

        Filter filter = filters.get(index);
        index++;
        filter.build(allTalkEntities, trackEntity, this);
    }
}
